<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript">
	$(document)
			.ready(
					function() {
						$(
								'input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea',
								'.form').iTextClear();
					});
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="CSS/Tree.css" />
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/css/tipswindown.css" />
<script type="text/javascript" src="js/jquery-ui-1.7.3.custom.min.js"></script>
<%-- <script type="text/javascript" src="${ctx}/js/ajaxupload_tx.3.6.js"></script> --%>
<script type="text/javascript" src="${ctx}/js/tipswindown.js"></script>
<script type="text/javascript" src="${ctx }/datepicker/WdatePicker.js"></script>
<!-- DATATABLES CSS END -->

<h1 class="page-title">员工奖惩管理 - 申请</h1>
<div class="container_12 clearfix leading">
	<div class="side grid_12 leading">
		<form id="post_form" name="post_form" class="form has-validation">
			<div class="clear"></div>
			<div class="clearfix">
				<label for="form-email" class="form-label">选择员工 <em>*</em></label>
				<div class="form-input">
					<input id="iput_empIds" type="hidden"
						name="examAward.employeeinfoWork.id"
						value="${examAward.employeeinfoWork.id}" /> <span
						id="employ_choose_name"
						style="display: inline-block; vertical-align: bottom; border-bottom: solid 1px #ccc; width: 150px; overflow: hidden; text-overflow: ellipsis;">${examAward.employeeinfoWork.baseId.name}</span>
					<a class="button" style="margin-top: 10px"
						href="javascript:void(0)" onclick="onShowDiv()"><span
						style="background: url(${ctx}/images/img/zoom.png)" class="icon">&nbsp;</span>选择</a>
				</div>
			</div>
			<div class="clear"></div>
			<div class="clearfix">
				<label for="form-email" class="form-label">奖惩类型 <em>*</em></label>
				<div class="form-input">
					<div class="radiogroup">
						<label><input type="radio" name="examAward.awardType"
							checked="checked" value="0"
							onchange="javascript:awardTypeChange(0)" /> 奖励</label> <label><input
							type="radio" name="examAward.awardType" value="1"
							onchange="javascript:awardTypeChange(1)" /> 惩罚</label>
					</div>
				</div>
			</div>
			<div class="clear"></div>
			<div class="clearfix">
				<label for="form-email" class="form-label">奖惩项目 <em>*</em></label>
				<div class="form-input">
					<select id="sel_awarditem" name="examAward.examAwardItem.id">

					</select>
				</div>
			</div>
			<div class="clear"></div>
			<div class="clearfix">
				<label for="form-birthday" class="form-label">奖惩时间 <em>*</em></label>
				<div class="form-input">
					<input type="text" id="award_date" name="award_date"
						required="required" placeholder="请输入日期" onfocus="WdatePicker()"
						value='<s:date name="#request.examAward.awardDate" format="yyyy-MM-dd"/>' />
				</div>
			</div>

			<div class="clear"></div>
			<div class="clearfix">
				<label for="form-email" class="form-label">奖惩理由 <em>*</em></label>
				<div class="form-input">
					<textarea name="examAward.awardReason" rows="5" required="required"
						id="awardReason" placeholder="请输入奖惩理由"></textarea>
				</div>
			</div>
			<div class="form-action clearfix">
				<button class="button" type="button" onclick="checkForm()">申请</button>
				<button class="button" type="reset">重置</button>
				<a class="button" href="javascript:void(0)"
					onclick="javascript:history.back()"><span
					style="background: url(${ctx}/images/img/arrow_undo.png)"
					class="icon">&nbsp;</span>返回</a>
			</div>
		</form>
	</div>
</div>

<div class="clear"></div>

<script type="text/javascript">
	var workId = -1;
	
	function awardTypeChange(at){
		if(workId < 0){
			alert("请选择员工");
			return;
		}
		 $.getJSON("${ctx}/ajax/awarditem_list.xhtml?workId=" + workId + "&awardType=" + at, function(awardItems) {
            var obj = $("#sel_awarditem");
            obj.html("");
            var temp = "";
            if (awardItems != null && awardItems.length > 0) {
                $.each(awardItems, function(i, awardItem) {
                    temp += '<option value="'+ awardItem.id + '">' + awardItem.title + '</option>';
                    if(i == 0){
                    	$(obj).prev("span").html(awardItem.title);
                    }
                });
            }
            obj.html(temp);
        });
	}
	
	/**
	 * 选择员工
	 */
	function onShowDiv() {
		//$("#config-popover").css("width", 900);
		tipsWindown(
				"选择员工",
				"url:post?${ctx}/employee/staff_list.xhtml?operation=select&organizationId=${organizationId}",
				"900", "350", "true", "", "true", "text");
	}

	//员工选择框返回事件
	function onSelectEployee(eid, ename, wid) {
		//alert(eid+"----------"+ename+"----------"+wid);
		if (eid == undefined || ename == undefined || wid == undefined) {
			return;
		}
		$("#iput_empIds").val(wid);
		workId = wid;
		$("#employ_choose_name").html(ename);
		awardTypeChange(0);
	}

	function checkForm() {
		if ($("#iput_empIds").val() == null || $("#iput_empIds").val() == "") {
			alert("请选择员工");
			return;
		}
		if ($("#sel_awarditem").val() == null || $("#sel_awarditem").val() == "") {
			alert("请选择奖惩项目");
			return;
		}
		if ($("#award_date").val() == null || $("#effective_date").val() == "") {
			alert("请输入奖惩日期");
			return;
		}

		if ($("#awardReason").val() == null || $("#awardReason").val() == "") {
			alert("请输入奖惩理由");
			return;
		}

		var url = "${ctx}/exam/post_award.xhtml";
		$.ajax(url, {
			type : "POST",
			data : $("#post_form").serialize(),
			dataType : "html",
			cache : false,
			success : function(a) {
				alert("提交成功");
				//window.location.href = "${ctx}/index.xhtml#train/lecturer_main.xhtml?organizationId=${category.organization.id}";
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				alert('提交申请发生异常');
			},
			complete : function() {
			}
		});

	}
</script>
